﻿using System;
using log4net;
using Microsoft.Extensions.Caching.Memory;
using Moreeasi.TaskQueue;
using Prism.Events;
using Prism.Ioc;
using Modules.MSentEvent;
using Sorting.App.Models;
using Sorting.App.Models.Enum;
using Sorting.App.Services;
using Modules.Units;
using System.Threading.Tasks;
using Sorting.App.Models.Entity;

namespace Lm.Core.TaskQueue;


/// <summary>
/// 扫描任务队列
/// </summary>
public class PutDrugTask : UnitTask
{
    IEventAggregator _ea;
    private readonly IContainerExtension _container;

    public PutDrugTask(IEventAggregator ea, IContainerExtension container
       )
    {
        _ea = ea;
        _container = container;
    }
    private TQService tQService = new TQService();
    private TaskLogService _logService = new TaskLogService();
    public ILog log = LogManager.GetLogger(typeof(PutDrugTask));

    /// <summary>
    /// 任务处理
    /// </summary>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    public override void ExecuteNew()
    {

        //写入缓存
        var msg = AppsettingUnits.ScanInfo;
        if (string.IsNullOrEmpty(msg.Trim()))
        {
            return;
        }
        this.State = EnumTaskState.Running;
        log.Info($"扫描时间{DateTime.Now}");

        //根据扫描的SNNO查询贴签机对应的病区编码
        var tqres = new BarcodeWardDto
        {
            Barcode = msg,
        };
        _ea.GetEvent<ViewModelSentEvent>().Publish(new MessageModel
        {
            Code = EnumMessageType.ME104,
            Data = tqres,
            Message = $"扫描信息【{tqres.WardCode}】"
        });

        AppsettingUnits.ScanInfo=String.Empty;
        this.State = EnumTaskState.Sucess;

    }
}